<?php 
class setting_models_adminMenu extends CI_Model{
public function listItems($search,$parent=0,$result=array()){
		$this->db->select('*')->
						from('admin_menu');
		if(!empty($search)){
			$this->db->like('name', $search);
			$this->db->or_like('class', $search);
			$get= $this->db->get();
			return $get->result();
		}
		$this->db->where('parent',$parent);

		$this->db->order_by('order','ASC');
		$get= $this->db->get();
		foreach( $get->result() as $row){
			$result[]=$row;
			$result=self::listItems($search,$row->id,$result);
		}
		return $result;
	}
	public function listIdShameParent($id){
		$sql="SELECT id FROM admin_menu where parent =(SELECT parent FROM admin_menu WHERE id='$id') ORDER BY `order` ASC";
		$get=$this->db->query($sql);
		$result=array();
		foreach( $get->result() as $row)
			$result[]=$row->id;
		return $result;
	}
	public function updateOrder($OrderArrays){
		foreach ($OrderArrays as $id=>$Order )
			$this->db->where('id',$id)->update('admin_menu',$Order);
	}
	public function add_AdminMenu($data){
		$this->db->insert('admin_menu', $data);
		return $this->db->insert_id();
	}
	public function update_AdminMenu($data){
		if(isset($data['id'])){
			$this->db->where('id', $data['id']);
			unset($data['id']);
			$this->db->update('admin_menu', $data);
			return $this;
		}
	
	}
	public function get_categories($parent,$filter=''){
		$this->db->select('*')->
		from('admin_menu')->
		where(array('parent'=>$parent,'active'=>1))->
		order_by('order');
		if(!empty($filter)) $this->db->like('name', $filter);
		$get= $this->db->get();
		return $get->result();
	}

	public function delete_categories($id){
		if(isset($id)){
			$this->db->delete('admin_menu', array('id' => $id));
			return $this;
		}
	}
}